package com.orangelife.mobile.confirmOrder.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.curry.android.util.ImageDownloader;
import com.curry.orangelife.mobile.R;
import com.curry.android.adapter.FatherAdapter;
import com.orangelife.mobile.confirmOrder.activity.ShoppingConfirmOrderActivity;
import com.orangelife.mobile.constants.Constant;

import java.util.List;
import java.util.Map;

/**
 * 投诉建议列表的适配器
 *
 * @author yuyuxia
 *
 */

public class GoodsInfoListViewAdapter<T> extends FatherAdapter<T> {
    private List<Map<String, Object>> listGoods;/**单个商户的商品列表*/
    private Context context;
    private int goodsNumbers;/**单个商户的单个商品数量*/
    private ImageDownloader image = ImageDownloader.getImageDownloader();
    public GoodsInfoListViewAdapter(Context context,
                                   List<Map<String, Object>> listGoods
         ) {
         this.listGoods = listGoods;
         this.context = context;
    }

    @Override
    public int getCount() {
        return listGoods.size();
    }

    @Override
    public Object getItem(int position) {
        return listGoods.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressWarnings("unchecked")
    @Override
    public BaseAdapter setList(List<T> listGoods) {
        this.listGoods = (List<Map<String, Object>>) listGoods;
        return GoodsInfoListViewAdapter.this;
    }



    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            holder = new ViewHolder();
		    convertView = LayoutInflater.from(context).inflate(R.layout.item_order_detail, null);
            holder.tvTotalPrice = (TextView)convertView.findViewById(R.id.tvMarkerPrice);
            holder.tvUnitPrice = (TextView)convertView.findViewById(R.id.tvUnitPrice);
            holder.tvGoodsName = (TextView)convertView.findViewById(R.id.tvGoodsName);
            holder.tvSpecsName = (TextView)convertView.findViewById(R.id.tvSpecsName);
            holder.tvTotalNumber = (TextView)convertView.findViewById(R.id.tvTotalNumber);
            holder.ivGoods = (ImageView)convertView.findViewById(R.id.ivGoods);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        goodsNumbers = 1;
        holder.tvTotalNumber.setText("×"+goodsNumbers);
        holder.tvTotalPrice.setText(Constant.RMB_FLAG + listGoods.get(position).get("mkPrice").toString());
        holder.tvUnitPrice.setText(Constant.RMB_FLAG + listGoods.get(position).get("price").toString());
        holder.tvTotalPrice.getPaint().setFlags(
                Paint.STRIKE_THRU_TEXT_FLAG);
        image.download(listGoods.get(position).get("goodsLogo").toString().trim(),
                holder.ivGoods,
                ImageDownloader.ImageSize.IMAGE_SIZE_EXTRA_SMALL_RECTANGLE_JPG);
        holder.tvSpecsName.setText(listGoods.get(position).get("pdtDesc").toString());
        holder.tvTotalNumber.setText("数量" + listGoods.get(position).get(ShoppingConfirmOrderActivity.PRODUCT_NUMBER).toString());
        holder.tvGoodsName.setText(listGoods.get(position).get("goodsName").toString());
        return convertView;
    }

    class ViewHolder {
        private TextView tvTotalPrice;
        private TextView tvUnitPrice;
        private TextView tvGoodsName;
        private TextView tvSpecsName;
        private TextView tvTotalNumber;
        private ImageView ivGoods;
    }

}
